package com.hrm.controller;

import com.hrm.service.HrmPaymentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.RequestParam;
import com.hrm.util.PageView;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value = "/Pay")
public class HrmPaymentController {
    @Autowired
    protected HrmPaymentService hrmPaymentService;

    /**
     * 打开工资发放页面
     */
    @RequestMapping(value = "/hrmPaymentManage.html")
    public ModelAndView hrmPaymentManage(
            @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize)
    {
        Map<String, Object> params = new HashMap<String, Object>();
        PageView pageView = new PageView(pageNum);
        pageView.setPageSize(pageSize);

        ModelAndView mav = new ModelAndView("/hrmpayment");
        try {
            mav.addObject("pageView", hrmPaymentService.findEntityPageByParam(pageView, params));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 打开奖惩页面（各项标准）
     * @return
     */
    @RequestMapping(value = "/hrmPayRewardManage.html")
    public ModelAndView hrmPayRewardManage(
            @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "20") Integer pageSize)
    {
        Map<String, Object> params = new HashMap<String, Object>();
        PageView pageView = new PageView(pageNum);
        pageView.setPageSize(pageSize);

        ModelAndView mav = new ModelAndView("/hrmreward");
        try {
            mav.addObject("pageViewReward",hrmPaymentService.findEntityStandardPageByParam(pageView, params));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 根据id获取奖金信息
     * @param id
     * @return
     */
    @RequestMapping(value = "/hrmRewardId.post", method = RequestMethod.POST)
    @ResponseBody
    public ModelAndView hrmApartIdManage(Integer id) {
        ModelAndView mav = new ModelAndView("/hrmreward");
        try {
            mav.addObject("hrmReward", hrmPaymentService.getHrmReward(id));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mav;
    }

}
